Skip to content

Migrate CruiseControlMetricsReporterTest to TestContainers#2303

Merged
CCisGG merged 2 commits intolinkedin:mainfrom
kyguy:test-containers-migration
Oct 3, 2025
Merged

Migrate CruiseControlMetricsReporterTest to TestContainers#2303
CCisGG merged 2 commits intolinkedin:mainfrom
kyguy:test-containers-migration

Conversation

@kyguy
Copy link
Copy Markdown
Contributor

@kyguy kyguy commented Aug 11, 2025

Summary

  1. Why: As detailed in issue Migrate off internal Kafka APIs to Improve Compatibility and Maintainability #2282, the existing Cruise Control tests rely on the Kafka server wrapper class, CCEmbeddedBroker, which uses several non-public Kafka APIs. These internal APIs lack stability and compatibility guarantees, making it increasingly difficult to upgrade Kafka versions. As Kafka evolves, this reliance introduces upgrade friction, version lock-in, and a growing maintenance burden.

  2. What: This PR starts the migration of the Cruise Control tests away from internal Kafka APIs by refactoring the CruiseControlMetricsReporterTest to replace its dependency on the CCEmbeddedBroker class with the TestContainers Kafka module instead. This helps future-proof Cruise Control by easing upgrades to newer Kafka versions, expanding Kafka versions compatibility, and reducing the ongoing maintenance overhead.

If an approach looks good, passes review, and is merged, we can continue migrating the remaining test classes incrementally, one PR at a time, until we completely remove the dependency on private Kafka APIs in the Cruise Control tests.

Categorization

  • documentation
  • bugfix
  • new feature
  • refactor
  • security/CVE
  • other

This PR partially resolves #2282

@kyguy kyguy force-pushed the test-containers-migration branch 6 times, most recently from dbf97d8 to e0b2cb3 Compare August 20, 2025 20:57
@kyguy
Copy link
Copy Markdown
Contributor Author

kyguy commented Aug 21, 2025

Could one of the maintainers take a look at this PR and the referenced issue when you have a chance?
If it would be helpful, I’d be happy to tag some people in the community with Cruise Control or TestContainers experience to help with code review!

CC @mhratson @CCisGG

@CCisGG
Copy link
Copy Markdown
Contributor

CCisGG commented Aug 21, 2025

@kyguy The idea looks good to me. It would be super helpful if you could find some reviewers, and I'll give a +1 once this get reviewed. Thanks!

@kyguy
Copy link
Copy Markdown
Contributor Author

kyguy commented Aug 21, 2025

Hoping to tap into your expertise in Cruise Control and/or TestContainers, would you mind taking a look at this when you get a chance?

CC @ppatierno @fvaleri @ShubhamRwt @tomncooper @mimaison @see-quick @k-wall

Copy link
Copy Markdown

@see-quick see-quick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍. I have just a few comments to consider.

Comment thread .circleci/config.yml
Comment thread .circleci/config.yml Outdated
Copy link
Copy Markdown

@see-quick see-quick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Copy link
Copy Markdown
Contributor

@mimaison mimaison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I left a few suggestions and comments

Comment thread .circleci/config.yml Outdated
@kyguy kyguy force-pushed the test-containers-migration branch 2 times, most recently from 2147a3c to 1057e9f Compare August 27, 2025 20:52
Copy link
Copy Markdown
Contributor

@mimaison mimaison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates. I made another pass

@kyguy kyguy force-pushed the test-containers-migration branch 4 times, most recently from 79e4175 to b8b8fd4 Compare September 8, 2025 01:16
Copy link
Copy Markdown
Contributor

@mimaison mimaison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates! It's looking better, I just left a few more comments.

@kyguy kyguy force-pushed the test-containers-migration branch from e1284ad to b64ca60 Compare September 9, 2025 02:25
@mimaison
Copy link
Copy Markdown
Contributor

mimaison commented Sep 9, 2025

Thanks for the updates.

It looks like the latest changes have broken a test:

com.linkedin.kafka.cruisecontrol.TopicAnomalyIntegrationTest > testTopicAnomalyFinder[0] FAILED
    java.lang.NullPointerException
        at com.linkedin.kafka.cruisecontrol.KafkaCruiseControlVertxApp.serverUrl(KafkaCruiseControlVertxApp.java:31)
        at com.linkedin.kafka.cruisecontrol.KafkaCruiseControlApp.printStartupInfo(KafkaCruiseControlApp.java:79)
        at com.linkedin.kafka.cruisecontrol.KafkaCruiseControlVertxApp.start(KafkaCruiseControlVertxApp.java:58)
        at com.linkedin.kafka.cruisecontrol.CruiseControlIntegrationTestHarness.start(CruiseControlIntegrationTestHarness.java:47)
        at com.linkedin.kafka.cruisecontrol.TopicAnomalyIntegrationTest.setup(TopicAnomalyIntegrationTest.java:62)

@kyguy kyguy force-pushed the test-containers-migration branch from adc1908 to e168254 Compare September 10, 2025 15:28
@kyguy
Copy link
Copy Markdown
Contributor Author

kyguy commented Sep 11, 2025

Ready for another round of reviews, @k-wall @mimaison could you have another pass when you get a chance?

Comment thread .circleci/config.yml Outdated
Comment thread .circleci/config.yml Outdated
@kyguy kyguy force-pushed the test-containers-migration branch 3 times, most recently from 61bd8c3 to 13e8342 Compare September 11, 2025 20:19
Copy link
Copy Markdown
Contributor

@mimaison mimaison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Contributor

@k-wall k-wall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One final nit, but otherwise LGTM

@kyguy
Copy link
Copy Markdown
Contributor Author

kyguy commented Sep 12, 2025

Hey @CCisGG this PR has been tested, reviewed, and is ready to go!

Signed-off-by: Kyle Liberti <kliberti.us@gmail.com>
@kyguy kyguy force-pushed the test-containers-migration branch from 8b1bb0c to e2c328e Compare September 29, 2025 22:03
@kyguy
Copy link
Copy Markdown
Contributor Author

kyguy commented Oct 1, 2025

Hi @CCisGG, if you don’t have any objections, would you be okay with merging this PR?

Copy link
Copy Markdown

@danielgospodinow danielgospodinow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a shallow first look at the PR and left some comments. I'll revisit the PR soon to see if I can find anything deeper.

Btw, this is a fantastic initiative, IMO. Kudos for the effort!

// Selects or creates the Docker network used for Test Container communication.
// This is useful in CI environment like CircleCI where the Docker network needs to be shared with Test Container client.
private static final Network NETWORK = System.getenv("NETWORK_NAME") != null
? Network.builder().id(System.getenv("NETWORK_NAME")).build()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, setting the network ID using id(name) seems to be deprecated. 🤔

Copy link
Copy Markdown
Contributor Author

@kyguy kyguy Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, id(name) has been deprecated but it is required for connecting CircleCI jobs to TestContainer services. This is something I need to chase up with the TestContainers and CircleCI communities so we don't lose this functionality in the future or are presented an alternative path forward. I'll link an issue here.

Comment thread .circleci/config.yml
no_output_timeout: 15m
command: ./gradlew --no-daemon -PmaxParallelForks=1 build
command: |
export NETWORK_NAME="test_containers_network"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it mandatory to create and pass down NETWORK_NAME and CONTAINER_HOST?

If everything works fine without those two (in case the framework creates its own ephemeral resources), I'd personally prefer not having them for the sake of simplicity.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading the comments in CCContainerizedKraftCluster kind of explained the situation. It's basically good to have for CI. But I'm still not sure if it's mandatory or just good to have.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, these variables are mandatory for allowing the CircleCI job to find/connect to the containers created by TestContainers. I have just added some comment/Javadocs to make this more clear. Let me know what you think!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Makes sense. And the docs explain it well now. Thanks!

EXTERNAL_LISTENER_NAME + "://0.0.0.0:" + CONTAINER_EXTERNAL_LISTENER_PORT
);
this._bootstrapServers = generateBootstrapServersList(numOfBrokers, containerHostPorts);
adminClientProps.setProperty(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, _bootstrapServers);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's slightly odd that we're mutating an externally provided object that is only used here. It can cause side effects. Why not just craft the adminClientProps here in the constructor?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe we can pass a clone of adminClientProps.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or just have JavaDoc that mentions this behavior clearly.

Copy link
Copy Markdown
Contributor Author

@kyguy kyguy Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cloned it in the constructor and added a note in the latest commit, let me know if this will suffice!

Signed-off-by: Kyle Liberti <kliberti.us@gmail.com>
Copy link
Copy Markdown
Contributor

@CCisGG CCisGG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kyguy !

@CCisGG CCisGG merged commit 26b7c3a into linkedin:main Oct 3, 2025
6 checks passed
danielgospodinow pushed a commit to qbaware/cruise-control that referenced this pull request Oct 5, 2025
…2303)

* Migrate CruiseControlMetricsReporterTest to TestContainers

Signed-off-by: Kyle Liberti <kliberti.us@gmail.com>

* Addressing feedback - gp

Signed-off-by: Kyle Liberti <kliberti.us@gmail.com>

---------

Signed-off-by: Kyle Liberti <kliberti.us@gmail.com>
danielgospodinow pushed a commit to qbaware/cruise-control that referenced this pull request Oct 5, 2025
…2303)

* Migrate CruiseControlMetricsReporterTest to TestContainers

Signed-off-by: Kyle Liberti <kliberti.us@gmail.com>

* Addressing feedback - gp

Signed-off-by: Kyle Liberti <kliberti.us@gmail.com>

---------

Signed-off-by: Kyle Liberti <kliberti.us@gmail.com>
JvD-Ericsson pushed a commit to Nordix/cruise-control that referenced this pull request Oct 15, 2025
…2303)

* Migrate CruiseControlMetricsReporterTest to TestContainers

Signed-off-by: Kyle Liberti <kliberti.us@gmail.com>

* Addressing feedback - gp

Signed-off-by: Kyle Liberti <kliberti.us@gmail.com>

---------

Signed-off-by: Kyle Liberti <kliberti.us@gmail.com>
georgew5656 pushed a commit to DataDog/cruise-control that referenced this pull request Dec 4, 2025
…2303)

* Migrate CruiseControlMetricsReporterTest to TestContainers

Signed-off-by: Kyle Liberti <kliberti.us@gmail.com>

* Addressing feedback - gp

Signed-off-by: Kyle Liberti <kliberti.us@gmail.com>

---------

Signed-off-by: Kyle Liberti <kliberti.us@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate off internal Kafka APIs to Improve Compatibility and Maintainability

6 participants